#include <iostream>

//https://leetcode.cn/problems/add-strings/

using namespace std;

class Solution {
public:
    string addStrings(string num1, string num2) {
        string::reverse_iterator s1 = num1.rbegin();
        string::reverse_iterator s2 = num2.rbegin();
        string str;
        for (int temp = 0; s1 < num1.rend() || s2 < num2.rend() || temp; ++s1, ++s2) {
            int n1 = s1 < num1.rend() ? *s1 - '0' : 0;
            int n2 = s2 < num2.rend() ? *s2 - '0' : 0;
            int num = n1 + n2 + temp;
            temp = num > 9 ? 1 : 0;
            str += num % 10 + '0';
        }
        reverse(str.begin(), str.end());
        return str;
    }
};

int main() {
    Solution s;
    cout << s.addStrings("1", "9") << endl;

    return 0;
}


